var myAdfLinks = [];

function addMyListener(element, eventName, handler) {
  if (element.addEventListener) {
    element.addEventListener(eventName, handler, false);
  }
  else if (element.attachEvent) {
    element.attachEvent('on' + eventName, handler);
  }
  else {
    element['on' + eventName] = handler;
  }
}

function initMyAdf() {
    for(var i=0; i<document.links.length; i++) {
        var lnk = document.links[i].toString();
        var iIndex = lnk.indexOf("://");
        if(iIndex == -1) {
            continue;
        }
        iIndex = lnk.indexOf("://", iIndex + 3);
        if(iIndex == -1) {
            continue;
        }
        iIndex = lnk.indexOf("/", iIndex + 3);
        if(iIndex == -1) {
            continue;
        }
        var ss = lnk.substring(iIndex);
        if(ss.length < 5) {
            continue;
        }
        myAdfLinks.push(lnk);
    }
    if(myAdfLinks.length > 0) {
        addMyListener(document.getElementById('my_adf_bottom_div'), 'click', function() {
            var iIndex = Math.floor((Math.random() * myAdfLinks.length));
            window.location = myAdfLinks[iIndex];
        });
    }
}
